package com.jwdf.uda.ui.activity;

import android.os.Bundle;
import android.view.View;

import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.event.MessageNoticeEvent;
import com.jwdf.uda.http.AHttpService;
import com.jwdf.uda.http.HttpHelper;
import com.jwdf.uda.http.action.UserMessageDetailAction;
import com.jwdf.uda.ui.fragment.base.BaseFragment;
import com.jwdf.uda.ui.fragment.user.MessageFragment;
import com.jwdf.uda.utils.EventBusUtil;
import com.jwdf.uda.view.dialog.SysMsgAlertDialog;
import retrofit2.Response;

/**
 * 类说明：消息通知
 * 作者：huangqiuxin on 2016/5/17 15:31
 * 邮箱：648859026@qq.com
 */
public class MessageActivity extends AbsTitleBarActivity {

    private static final String EXTRA_ID = "id";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int messageId = getIntent().getIntExtra(EXTRA_ID, 0);
        if (messageId != 0) {
            onNewRequestCall(UserMessageDetailAction.newInstance(this, messageId).request(new AHttpService.IResCallback<PbBean.PbResUserGetMessageDetail>() {
                @Override
                public void onCallback(int resultCode, Response<PbBean.PbResUserGetMessageDetail> response, PbBean.PbBaseServerInfo baseServerInfo) {
                    if (HttpHelper.showError(MessageActivity.this, resultCode, baseServerInfo, R.string.error_net)) {
                        return;
                    }
                    PbBean.PbResUserGetMessageDetail result=response.body();
                    if(result!=null){
                        showAlertDialog(result.getMessageDetail().getContent());
                    }
                }
            }));
        }
    }

    private void showAlertDialog(String content) {
        SysMsgAlertDialog dialog = new SysMsgAlertDialog(this, content);
        dialog.show();
    }

    @Override
    protected String getTopTitle() {
        return getString(R.string.title_message);
    }

    @Override
    protected BaseFragment onCreateContentFragment() {
        return new MessageFragment();
    }

    @Override
    protected void setupTitleView() {
        setOperateTitle(getString(R.string.head_operate_all_read));
    }

    @Override
    public void onHeadActionClick(View view) {
        EventBusUtil.post(new MessageNoticeEvent(MessageNoticeEvent.READ_ALL_MESSAGE));
    }
}
